﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleToolApp
{
    public static class ProgressHelper
    {


        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static (double yearProgress,int days) YearProgress(DateTime currentDate)
        {

            // 获取当年第一天和最后一天
            DateTime startOfYear = new DateTime(currentDate.Year, 1, 1);
            DateTime endOfYear = new DateTime(currentDate.Year, 12, 31);

            // 计算已过天数和总天数
            int daysPassed = (currentDate - startOfYear).Days + 1; // 加1是因为当天也算
            int totalDaysInYear = (endOfYear - startOfYear).Days + 1; // 包括最后一天

            // 计算百分比
            double percentageOfYear = (double)daysPassed / totalDaysInYear * 100;

            return (Math.Round(percentageOfYear, 1), daysPassed);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static (double monthProgress, int days) MonthProgress(DateTime currentDate)
        {

            // 获取当月的第一天和最后一天
            DateTime startOfMonth = new DateTime(currentDate.Year, currentDate.Month, 1);
            DateTime endOfMonth = startOfMonth.AddMonths(1).AddDays(-1);

            // 计算已过天数和总天数
            int dayOfMonth = currentDate.Day; // 当前是当月的第几天
            int totalDaysInMonth = (endOfMonth - startOfMonth).Days + 1;

            // 计算当月百分比
            double percentageOfMonth = (double)dayOfMonth / totalDaysInMonth * 100;

            // 获取今天是星期几
            // string dayOfWeek = currentDate.DayOfWeek.ToString();

            return (Math.Round(percentageOfMonth, 1), dayOfMonth);

        }


        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static (double dayProgress, TimeSpan time) DayProgress(DateTime currentTime)
        {

            // 计算当天开始的时间（零点）
            DateTime startOfDay = new DateTime(currentTime.Year, currentTime.Month, currentTime.Day, 0, 0, 0);

            // 计算当天已过的秒数和总秒数
            double secondsPassed = (currentTime - startOfDay).TotalSeconds;
            double totalSecondsInDay = 24 * 60 * 60;

            // 计算当前时间是当日的百分比
            double percentageOfDay = (secondsPassed / totalSecondsInDay) * 100;

            return (Math.Round(percentageOfDay, 1), DateTime.Now.TimeOfDay);
        }



        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static (double weekProgress, int days) WeekProgress(DateTime currentDate)
        {


            // 获取本周的第一天（假设周一是本周的第一天）
            DayOfWeek firstDayOfWeek = DayOfWeek.Monday;
            DateTime startOfWeek = currentDate.Date;
            while (startOfWeek.DayOfWeek != firstDayOfWeek)
            {
                startOfWeek = startOfWeek.AddDays(-1);
            }

            // 计算本周的最后一天
            DateTime endOfWeek = startOfWeek.AddDays(6); // 一周有7天

            // 计算当前是本周的第几天
            int daysPassed = (currentDate - startOfWeek).Days + 1;
            int totalDaysInWeek = 7;

            // 计算当日是本周的百分比
            double percentageOfWeek = (double)daysPassed / totalDaysInWeek * 100;

            return (Math.Round(percentageOfWeek, 1), daysPassed);
        }

    }
}
